using System;
using System.IO;
using System.Net;
using System.Data;
using System.Drawing;
using System.Text;
using System.Collections;
using System.ComponentModel;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Drawing.Printing;

namespace smartBrowser.Util
{
    class WebPageFetcher
    {
        private WebPageFetcher() { }

        public static string FecthPage(Uri uri)
        {
            try
            {
                StringBuilder sb = new StringBuilder();

                byte[] buf = new byte[8192];

                HttpWebRequest request = (HttpWebRequest)
                    WebRequest.Create(uri.AbsoluteUri);


                HttpWebResponse response = (HttpWebResponse)
                    request.GetResponse();



                Stream resStream = response.GetResponseStream();

                string tempString = null;
                int count = 0;

                do
                {
                    count = resStream.Read(buf, 0, buf.Length);

                    if (count != 0)
                    {
                        tempString = Encoding.ASCII.GetString(buf, 0, count);

                        sb.Append(tempString);
                    }
                }
                while (count > 0);

                return sb.ToString();
            }
            catch (Exception exception)
            {
                Console.Out.WriteLine("Error Getting a http request. The reason is: " + exception.Message);
            }

            return null;
        }
    }
}
